package com.wn.controller;


import com.common.entity.Order;
import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.github.pagehelper.PageInfo;
import com.wn.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController  {
    @Autowired
    private OrderService orderService;
    /**
     * @ClassName
     * @Description : 分页查询订单信息
     * @param: pageParam
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("searchSomeByPageOrder")
    @ApiOperation("分页查询订单信息")
    public Rsp searchSomeByPageOrder(@RequestBody PageParam<Order> order,
                                     @RequestHeader("token") String token){
        System.out.println(order.toString());
        PageInfo<Order> pg = orderService.searchSomeByPage(order);
        return Rsp.success(pg);
    }

    /**
     * @ClassName
     * @Description :根据id查询订单信息
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("getOneByIdOrder")
    @ApiOperation("根据id查询订单信息")
    public Rsp getOneByIdOrder(@RequestParam("id") String id,
                               @RequestHeader("token") String token){
        Order oneById = orderService.getOneById(id);
        return Rsp.success(oneById);
    }

    /**
     * @ClassName
     * @Description : addOne添加订单
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PutMapping("addOneOrder")
    @ApiOperation("添加订单")
    public Rsp addOneOrder(@RequestBody Order order,
            @RequestHeader("token") String token){
        return orderService.addOne(order);
    }

    /**
     * @ClassName
     * @Description : addOne添加订单
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PutMapping("bookingOrder")
    @ApiOperation("预下单")
    public Rsp bookingOrder(@RequestBody Order order,
                           @RequestHeader("token") String token){
        return orderService.bookingOrder(order);
    }

    /**
     * @ClassName
     * @Description : refundOrder退款
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("refundOrder")
    @ApiOperation("退款")
    public Rsp refundOrder(@RequestBody Order order,
                            @RequestHeader("token") String token){
        System.out.println(order.toString());
        return orderService.test_trade_refund(order);
    }

    /**
     * @ClassName
     * @Description : update修改订单
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("updateOrder")
    @ApiOperation("修改订单")
    public Rsp updateOrder(@RequestBody Order order,
                           @RequestHeader("token") String token){
        return orderService.update(order);
    }


    /**
     * @ClassName
     * @Description : deleteLogical逻辑删除计划
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("deleteLogicalOrder")
    @ApiOperation("逻辑删除订单")
    public Rsp deleteLogicalOrder(@RequestBody Order order,
                                  @RequestHeader("token") String token){
        return orderService.deleteLogical(order);
    }
    /**
     * @ClassName
     * @Description : 修改订单状态
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
    */

    @PostMapping("/updateOrderStatus")
    @ApiOperation("修改订单状态")
    public Rsp updateOrderStatus(@RequestBody Order order) {
        System.out.println(order.getOrderNo()+order.getStatus());
        Rsp rsp = orderService.updateOrderStatus(order.getOrderNo(), order.getStatus());
        return rsp;
    }

    @PostMapping("/queryno")
    @ApiOperation("查询订单状态")
    public Rsp queryno(@RequestBody Order order) {
        Rsp rsp = orderService.queryOrderStatusFromDB(order.getOrderNo());
        return rsp;
    }

    @PostMapping("/queryOrderByUserId")
    @ApiOperation("根据用户id查询订单")
    public Rsp queryOrderByUserId(@RequestBody Order order) {
        Rsp rsp = orderService.queryByCreateUserId(order.getCreateUserId());
        return rsp;
    }

}
